--
-- @Author:      feilong
-- @DateTime:    2019-17-30 23:05:48
-- @Description: 分配桌子


local skynet = require "skynet"
local config_query = require("configquery")

local TableManager = class("TableManager")

---------------------------------------------------------
-- Private
---------------------------------------------------------
function TableManager:ctor(message_dispatch, node_message)
    self.message_dispatch = message_dispatch    
    self.node_message = node_message

    self.table_list = {}    

	self:register()
end

--注册本服务里的消息
function TableManager:register()
	-- self.message_dispatch:registerSelf("enterHallReq", handler(self,self.enterHallReq))

end

function TableManager:start()
	self.user_manager = global.user_manager
	self.node_message = global.node_message
end

function TableManager:assignTable(user_id, room_id)
	--根据房间的配置限制来分配
	local room_data = config_query.room_data[room_id]
	print("______room_data__", room_data)
	if not self.table_list[room_id] then 
		self.table_list[room_id] = 0
	end
	self.table_list[room_id] = self.table_list[room_id] + 1
	return room_id * 100 + self.table_list[room_id]
end

--启动百人场
function TableManager:createGame(room_id, user_id)
	local room_data = config_query.room_data[room_id]
	if not room_data then 
		return
	end
	self.node_message:broadcastToServer("gameserver", "create_game", room_id, user_id)
end


--同步游戏节点桌子信息
function TableManager:syncTableState()
	-- 
	local function sync()
		while true do
			--todo
			self.node_message:broadcastToServer("gameserver", "sync_state")
		end
	end
	skynet.fork(sync)

end


---------------------------------------------------------
-- CMD
---------------------------------------------------------




return TableManager